package com.we823.cms.repository.service.extension;

import com.github.pagehelper.PageInfo;
import com.we823.cms.common.web.pageable.PageRequest;
import com.we823.cms.common.web.pageable.Sort;
import com.we823.cms.model.extension.Brand;
import com.we823.cms.repository.dao.extension.BrandMapper;
import com.we823.cms.repository.service.AbstractBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("brandService")
@Scope("prototype")
public class BrandService extends AbstractBaseService<Brand, Integer> {

	private BrandMapper brandMapper;
	
	@Autowired
	public BrandService(BrandMapper brandMapper) {
		super(brandMapper);
		this.brandMapper = brandMapper;
	}

	public List<Brand> findByShowIndex(int showIndex){
		Brand brand = new Brand();
		brand.setShowIndex(showIndex);
		return brandMapper.select(brand);
	}
	public List<Brand> findByShowIndex(int showIndex, Sort sort) {
		setSortInfo(sort);
		return this.findByShowIndex(showIndex);
	}

	public PageInfo<Brand> findByShowIndex(int showIndex, PageRequest pageRequest) {
		setPageInfo(pageRequest);
		return new PageInfo<>(this.findByShowIndex(showIndex));
	}

	public void updateShowIndex(int id, int showIndex) {
		Brand brand = new Brand();
		brand.setId(id);
		brand.setShowIndex(showIndex);
		brandMapper.updateByPrimaryKeySelective(brand);
	}
}
